X diff = (long) min ((int) diff, sct[ntn[country].capx][ntn[country].capy].people/2);
X
X if(ntn[country].tgold<0 || ntn[country].tiron<0) if(diff > 0) diff=0;
X
X#ifdef DEBUG
X printf("\tadding %d men to garrison (too few men on garrison)\n",diff);
X#endif DEBUG
X
X sct[ntn[country].capx][ntn[country].capy].people-=diff;
X ASOLD+=diff;
X ntn[country].tciv-=diff;
X ntn[country].tmil+=diff;
X if(magic(country,WARRIOR)==1) /* take WARRIOR power into account */
X ntn[country].tgold -= (diff * *(u_encost + (ATYPE%100))) / 2;
X else ntn[country].tgold-=diff* *(u_encost + (ATYPE%100));
X ntn[country].tiron-=(diff* *(u_eniron + (ATYPE%100)));
X#ifdef DEBUG
X if(ASOLD < 0) printf("error 2... ASOLD=%d <0\n",ASOLD);
X#endif DEBUG
X }
X /*else split garrison army if 1.25* needed number*/
X else if(ASOLD *4 > 5*ideal){
X /*diff here is a negative number*/
X diff=((4*ASOLD)-(5*ideal))/4;
X#ifdef DEBUG
X printf("\tsplit garrison of %d men\n",diff);
X#endif DEBUG
X free=0;
X ASOLD-=diff;
X#ifdef DEBUG
X if(ASOLD < 0) printf("error... subtracting %d from %d\n",diff,ASOLD);
X#endif DEBUG
X ntn[country].tmil-=diff;
X ntn[country].tciv+=diff;
X sct[ntn[country].capx][ntn[country].capy].people+=diff;
X /*I add back gold as armies get redone anyway*/
X ntn[country].tiron += (diff* *(u_eniron + (ATYPE%100)));
X if(magic(country,WARRIOR)==1) /* WARRIOR power */
X ntn[country].tgold+=(diff* *(u_encost + (ATYPE%100))) / 2;
X else ntn[country].tgold+=diff* *(u_encost + (ATYPE%100));
X }
X#ifdef DEBUG
X else printf("\tno action - ASOLD (%d) ~= ideal (%d)\n",ASOLD,ideal);
X printf("\tFinal Garrison Army %d (%s) type is %s men is %d\n",armynum,ntn[country].name,*(unittype+(ATYPE)),ASOLD);
X#endif DEBUG
X
X /*build ships and/or armies*/
X done=FALSE;
X ideal = ntn[country].tciv * peace / (10 * MILRATIO);
X if(ntn[country].tgold<0) { ideal*=4; ideal/=5; }
X#ifdef DEBUG
X printf("\t%s total military is %d -> ideal is %d\n",ntn[country].name,ntn[country].tmil,ideal);
X check(__LINE__);
X#endif DEBUG
X /*if < ideal build new army in the capitol - if possible*/
X if(ntn[country].tmil < ((4*ideal)/5)) {
X for(armynum=1;armynum<MAXARM;armynum++)
X if((done==FALSE)&&(ASOLD==0)) {
X done=TRUE;
X ATYPE=A_INFANTRY;
X ASOLD = min ((int) (ideal-ntn[country].tmil), (int) (ntn[country].tiron/ (*(u_eniron + (ATYPE%100)))));
X
X ASOLD = min (ASOLD,sct[ntn[country].capx][ntn[country].capy].people/2);
X ASOLD = min (ASOLD, (int) (ntn[country].tgold/ *(u_encost+(ATYPE%100))));
X if(ASOLD>0){
X#ifdef DEBUG
Xprintf("\tnot enough soldiers - build new army %d with %d men\n",armynum,ASOLD);
X#endif DEBUG
X ntn[country].tiron-=(ASOLD* *(u_eniron + (ATYPE%100)));
X AXLOC= ntn[country].capx;
X AYLOC= ntn[country].capy;
X ntn[country].tmil += ASOLD;
X ntn[country].tciv -= ASOLD;
X if(magic(country,WARRIOR)==1) /* WARRIOR power */
X ntn[country].tgold-=(ASOLD* *(u_encost + (ATYPE%100))) / 2;
X else ntn[country].tgold-=ASOLD* *(u_encost + (ATYPE%100));
X sct[AXLOC][AYLOC].people-=ASOLD;
X ASTAT= DEFEND;
X AMOVE=0;
X }
X else ASOLD=0;
X }
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X } else if(ntn[country].tmil > (6*ideal/5)){
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X /*disband a pseudo-random army*/
X done=FALSE;
X diff=ntn[country].tmil-(6*ideal/5);
X#ifdef DEBUG
X if(ASOLD < 0) printf("\ndisbanding pseudo random army of about %d men\n",diff);
X#endif DEBUG
X for(armynum=1;armynum<MAXARM;armynum++){
X if((done==FALSE)
X &&(ASOLD>0)
X &&(ATYPE!=A_MILITIA)
X &&(sct[AXLOC][AYLOC].owner==country)
X &&((sct[AXLOC][AYLOC].gold>4)
X ||(sct[AXLOC][AYLOC].iron>4)
X ||(sct[AXLOC][AYLOC].designation==DCITY))
X &&(ASOLD<=diff)){
X#ifdef DEBUG
X printf("\ttoo many soldiers eliminate army %d (%d men)\n",armynum,ASOLD);
X#endif DEBUG
X diff-=ASOLD;
X sct[AXLOC][AYLOC].people+=ASOLD;
X ntn[country].tmil -= ASOLD;
X ntn[country].tciv += ASOLD;
X ASOLD=0;
X if(diff<=50) done=TRUE;
X }
X#ifdef DEBUG
X if(ASOLD < 0) printf("error X... ASOLD=%d <0\n",ASOLD);
X#endif DEBUG
X }
X }
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X#ifdef DEBUG
X printf("\twhew... new tmil is %d\n",ntn[country].tmil);
X#endif DEBUG
X
X /*resize armies */
X /*maximum npc army is 200 or tmil/20, minimum is 50*/
X for(armynum=1;armynum<MAXARM;armynum++){
X if((ASOLD>200)&&(ASOLD>ntn[country].tmil/20)) {
X free=FALSE;
X for(i=1;i<MAXARM;i++){
X if((free==0)&&(ntn[country].arm[i].sold==0)){
X free=1;
X ASOLD/=2;
X ATYPE=A_INFANTRY;
X ntn[country].arm[i].sold = ASOLD;
X ntn[country].arm[i].unittyp = A_INFANTRY;
X ntn[country].arm[i].smove = AMOVE;
X ntn[country].arm[i].stat = DEFEND;
X ntn[country].arm[i].xloc = AXLOC;
X ntn[country].arm[i].yloc = AYLOC;
X }
X }
X }
X /*minimum npc army is 50, merge them*/
X else if(ASOLD<50) {
X free=0;
X for(i=1;i<MAXARM;i++){
X if((ntn[country].arm[i].sold>0)
X &&(ntn[country].arm[i].xloc==AXLOC)
X &&(ntn[country].arm[i].yloc==AYLOC)
X &&(ntn[country].arm[i].unittyp==ATYPE)
X &&(i!=armynum)&&(free==0)){
X free=1;
X ntn[country].arm[i].sold += ASOLD;
X ntn[country].arm[i].unittyp=A_INFANTRY;
X ASOLD=0;
X }
X }
X }
X }
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X
X /* assure that militia unit resides in each city */
X for(armynum=0;armynum<MAXARM;armynum++)
X if((ASOLD>0)&&(ATYPE==A_MILITIA)){
X#ifdef DEBUG
X printf("\t\t%s army %d (now %d men - populace %d)\n",unittype[ATYPE],armynum,ASOLD,sct[AXLOC][AYLOC].people);
X#endif DEBUG
X if((sct[AXLOC][AYLOC].designation!=DCITY)
X &&(sct[AXLOC][AYLOC].designation!=DCAPITOL)){
X#ifdef DEBUG
X printf("\teliminating %s army %d as %d %d is des:%c alt:%c own:%d\n",unittype[ATYPE],armynum,AXLOC,AYLOC,sct[AXLOC][AYLOC].designation,sct[AXLOC][AYLOC].altitude,sct[AXLOC][AYLOC].owner);
X#endif DEBUG
X if(sct[AXLOC][AYLOC].owner == country)
X sct[AXLOC][AYLOC].people+=ASOLD;
X else
X sct[ntn[country].capx][ntn[country].capy].people+=ASOLD;
X ASOLD=0;
X }
X }
X
X if(ntn[country].tgold > 0)
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if((sct[x][y].owner==country)
X &&((sct[x][y].designation==DCITY)||(sct[x][y].designation==DCAPITOL))){
X free=FALSE;
X for(armynum=0;armynum<MAXARM;armynum++){
X if((ASOLD>0)
X &&(AXLOC==x)&&(AYLOC==y)
X &&(ATYPE==A_MILITIA)) {
X free=TRUE;
X break;
X }
X }
X if(free==FALSE) { /* draft a new militia army */
X for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD==0){
X ATYPE=A_MILITIA;
X AXLOC=x;
X AYLOC=y;
X free=TRUE;
X break;
X }
X }
X if((free==TRUE)) {
X /* want to add ideal troops */
X ideal = sct[x][y].people/MILINCITY - ASOLD;
X ideal = min(ideal, 250);
X if(ideal>0){
X if(magic(country,WARRIOR)==TRUE){ /* WARRIOR power */
X ntn[country].tgold-=
X (ideal* *(u_encost+ATYPE))/2;
X } else {
X ntn[country].tgold-=
X ideal* *(u_encost + ATYPE);
X }
X }
X ASOLD+=ideal;
X ASTAT=GARRISON;
X#ifdef DEBUG
X if(ATYPE!=A_MILITIA) printf("ERROR - NOT MILITIA\n");
X printf("\tadding %d troops to %s army %d (now %d men - populace %d)\n",ideal,unittype[ATYPE],armynum,ASOLD,sct[x][y].people);
X#endif DEBUG
X }
X }
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X
X /* if archer power - all units are archers */
X if(magic(country,ARCHER)==1)
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD>0)&&(ATYPE!=A_MILITIA)) ATYPE=A_ARCHER;
X}
X
Xvoid
Xgetdstatus()
X{
X int x,oldstat[MAXNTN];
X
X if(ntn[country].active<=1) return;
X
X for(x=1;x<MAXNTN;x++) {
X oldstat[x] = ntn[country].dstatus[x];
X /*if they at war with you go to war with them*/
X if(ntn[x].dstatus[country]>=WAR) {
X if(ntn[country].dstatus[x]<WAR)
X fprintf(fnews,"2.\tnation %s returns %s's declaration of war\n",ntn[country].name,ntn[x].name);
X
X ntn[country].dstatus[x]=WAR;
X } else
X if((ntn[country].dstatus[x]!=UNMET)
X &&(ntn[country].dstatus[x]!=JIHAD)
X &&(ntn[country].dstatus[x]!=CONFEDERACY)
X &&(ntn[country].active!=1)){
X if((ntn[x].tmil>4*ntn[country].tmil)
X &&(ntn[x].score>4*ntn[country].score)){
X if(rand()%3==0) {
X ntn[country].dstatus[x]=WAR;
X } else if(rand()%8==0) {
X ntn[country].dstatus[x]=JIHAD;
X }
X }
X /*if 2* mil and 2* score then not like them*/
X else if((ntn[x].tmil>2*ntn[country].tmil)
X &&(ntn[x].score>2*ntn[country].score)){
X if((ntn[country].dstatus[x]!=WAR)
X &&(ntn[x].race!=ntn[country].race)){
X if(rand()%3==0)
X ntn[country].dstatus[x]++;
X }
X }
X /*adjust based on your status with them*/
X if((ntn[country].dstatus[x]==WAR)
X &&(ntn[x].dstatus[country]<WAR))
X if(rand()%3==0) ntn[country].dstatus[x]--;
X
X if((ntn[country].dstatus[x]<WAR)
X &&(ntn[country].dstatus[x]>ALLIED)){
X if(ntn[x].dstatus[country]>1+ntn[country].dstatus[x]){
X if(rand()%3==0)
X ntn[country].dstatus[x]++;
X }
X else
X if(ntn[x].dstatus[country]+1<ntn[country].dstatus[x]){
X if(rand()%3==0)
X ntn[country].dstatus[x]--;
X }
X if(ntn[x].race==ntn[country].race)
X if(rand()%3==0)
X ntn[country].dstatus[x]--;
X }
X if(rand()%6==0) {
X if(ntn[country].dstatus[x]!=JIHAD)
X ntn[country].dstatus[x]++;
X }
X else if((rand()%5==0)
X &&(ntn[country].dstatus[x]!=CONFEDERACY)) {
X ntn[country].dstatus[x]--;
X }
X }
X }
X
X for(x=1;x<MAXNTN;x++)
X if(ntn[x].active>1){
X if((rand()%5==0)
X &&(ntn[x].dstatus[country]==WAR)
X &&(ntn[country].dstatus[x]==WAR)) {
X ntn[x].dstatus[country]=HOSTILE;
X ntn[country].dstatus[x]=HOSTILE;
X fprintf(fnews,"2.\tnation %s and %s announce ceasefire\n",ntn[country].name,ntn[x].name);
X } else if((oldstat[x]==WAR)&&(ntn[country].dstatus[x]==WAR)){
X fprintf(fnews,"2.\tnation %s stays at war with %s\n",ntn[country].name,ntn[x].name);
X } else if((oldstat[x]<WAR)&&(ntn[country].dstatus[x]==WAR)){
X fprintf(fnews,"2.\tnation %s goes to war with %s\n",ntn[country].name,ntn[x].name);
X } else if((oldstat[x]!=JIHAD)&&(ntn[country].dstatus[x]==JIHAD)){
X fprintf(fnews,"2.\tnation %s announces a jihad with %s\n",ntn[country].name,ntn[x].name);
X }
X }
X}
X
Xint
Xnationrun()
X{
X int goldthresh,ironthresh,citythresh;
X int armynum,loop;
X int x,y,i;
X long zz;
X
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X prep(country);
X
X /* is there an error*/
X if((sct[ntn[country].capx][ntn[country].capy].owner==country)
X &&(sct[ntn[country].capx][ntn[country].capy].designation!=DCAPITOL)){
X sct[ntn[country].capx][ntn[country].capy].designation=DCAPITOL;
X }
X
X getdstatus();
X
X /*move units */
X /*are they at war with any normal countries*/
X peace=0;
X for(i=1;i<MAXNTN;i++) if(ntn[country].dstatus[i]>peace)
X peace=ntn[country].dstatus[i];
X
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X if(peace<WAR){
X peace=8;
X pceattr();
X } else {
X /*if war then attack &/or expand */
X peace=12;
X /*are they attacking or defending */
X if(ntn[country].tmil==0) defattr();
X else for(x=0;x<MAXNTN;x++) if(ntn[country].dstatus[x]>HOSTILE){
X if(100*(ntn[country].tmil*(ntn[country].aplus+100))/((ntn[country].tmil*(ntn[country].aplus+100))+(ntn[x].tmil*(ntn[x].dplus+100)))>rand()%100){
X /*attacker*/
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD>0)&&(ATYPE!=A_MILITIA))
X ASTAT=ATTACK;
X atkattr();
X }
X /*defender*/
X else {
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD>0)&&(ATYPE!=A_MILITIA)){
X if(ASOLD<350) ASTAT=DEFEND;
X else ASTAT=ATTACK;
X }
X defattr();
X }
X }
X }
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD!=0)
X &&(ATYPE!=A_MILITIA)) armymove(armynum);
X
X /* INTELLIGENT SECTOR REDESIGNATION */
X if(ntn[country].active!=1) { /* no pc's */
X goldthresh=4;
X ironthresh=4;
X citythresh=10;
X for(loop=1;loop<5;loop++) {
X#ifdef DEBUG
X printf("\tnpcredes(): country %s, food %ld gold %d, iron %d, city %d\n",ntn[country].name,spread.food,goldthresh,ironthresh,citythresh);
X#endif DEBUG
X
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if((sct[x][y].owner==country)
X &&(is_habitable(x,y)))
X n_redes(x,y,goldthresh,ironthresh,citythresh);
X
X spreadsheet(country);
X
X if(spread.food < spread.civilians * 2L) {
X goldthresh++;
X ironthresh++;
X citythresh--;
X } else if(spread.food > spread.civilians * 3L) {
X if(rand()%2==0) goldthresh--;
X else ironthresh--;
X if(goldthresh==0) goldthresh=1;
X if(ironthresh==0) ironthresh=1;
X citythresh++;
X }
X else break;
X }
X }
X
X /*build forts in any cities*/
X if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if(((sct[x][y].designation==DCITY)
X ||(sct[x][y].designation==DCAPITOL))
X &&(sct[x][y].owner==country)
X &&(sct[x][y].fortress<10)
X &&(ntn[country].tgold>10000)
X &&(rand()%5==0)
X &&(sct[x][y].fortress<(sct[x][y].people%1000)))
X sct[x][y].fortress++;
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X /*redo mil*/
X if(ntn[country].active!=1) redomil();
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X
X /*buy new powers and/or new weapons*/
X if(getmgkcost(M_MIL,country) < getmgkcost(M_CIV,country)){
X if(ntn[country].jewels > getmgkcost(M_MIL,country)) {
X ntn[country].jewels-=getmgkcost(M_MIL,country);
X if((zz=getmagic(M_MIL))!=0){
X fprintf(fnews,"1.\tnation %s gets combat power number %d\n",ntn[country].name,zz);
X printf("\tnation %s gets combat power number %d\n",ntn[country].name,zz);
X exenewmgk(zz);
X } else if((zz=getmagic(M_MIL))!=0){
X fprintf(fnews,"1.\tnation %s gets combat power number %d\n",ntn[country].name,zz);
X printf("\tnation %s gets combat power number %d\n",ntn[country].name,zz);
X exenewmgk(zz);
X }
X else ntn[country].jewels+=getmgkcost(M_MIL,country);
X }
X } else {
X if(ntn[country].jewels > getmgkcost(M_CIV,country)) {
X ntn[country].jewels-=getmgkcost(M_CIV,country);
X if((zz=getmagic(M_CIV))!=0){
X fprintf(fnews,"1.\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
X printf("\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
X exenewmgk(zz);
X }
X else if((zz=getmagic(M_CIV))!=0){
X fprintf(fnews,"1.\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
X printf("\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
X exenewmgk(zz);
X }
X else ntn[country].jewels+=getmgkcost(M_CIV,country);
X }
X }
X
X#ifdef DEBUG
X check(__LINE__);
X#endif DEBUG
X if(magic(country,VAMPIRE)!=1) {
X i=0;
X if(magic(country,WARLORD)==1) i=30;
X else if(magic(country,CAPTAIN)==1) i=20;
X else if(magic(country,WARRIOR)==1) i=10;
X x = max ( ntn[country].aplus-i, 10 ) / 10;
X /* SHOULD USE spread.iron but it didnt work right */
X if(ntn[country].tiron > 3 * IRONORE * ntn[country].tmil*x*x){
X ntn[country].aplus+=1;
X ntn[country].dplus+=1;
X ntn[country].tiron-=2*IRONORE*ntn[country].tmil*x*x;
X printf("\tnation %s buys +1 percent attack and defence\n",ntn[country].name);
X }
X }
X}
X
X/* make sectors of those with whom you are peaceful attr = 1 */
Xn_atpeace()
X{
X register int x,y;
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if((sct[x][y].owner!=0)
X &&(ntn[country].dstatus[sct[x][y].owner]<WAR)
X &&(abs(x-ntn[country].capx)>2)
X &&(abs(y-ntn[country].capy)>2))
X attr[x][y]=1;
X}
X
X/* you are too far from capitol */
Xn_toofar()
X{
X register int x,y;
X for(x=ntn[country].capx+NPCTOOFAR;x<MAPX;x++)
X for(y=0;y<MAPY;y++) if(ONMAP)
X attr[x][y]=1;
X for(y=ntn[country].capy+NPCTOOFAR;y<MAPY;y++)
X for(x=0;x<MAPY;x++) if(ONMAP)
X attr[x][y]=1;
X for(x=0;x<ntn[country].capx-NPCTOOFAR;x++)
X for(y=0;y<MAPY;y++) if(ONMAP)
X attr[x][y]=1;
X for(y=0;y<ntn[country].capy-NPCTOOFAR;y++)
X for(x=0;x<MAPY;x++) if(ONMAP)
X attr[x][y]=1;
X}
X
X/* take undefended land */
Xn_unowned()
X{
X register int x,y;
X int dist;
X
X /* around capitol */
X for(x=ntn[country].capx-4;x<=ntn[country].capx+4;x++){
X for(y=ntn[country].capy-4;y<=ntn[country].capy+4;y++){
X if((ONMAP)&&(sct[x][y].owner==0)) {
X /* find distance btwn x,y and cap */
X dist=abs(x-ntn[country].capx)+abs(y,ntn[country].capy);
X if(dist<10) attr[x][y]+= 500 - 50*dist;
X }
X }
X }
X
X for(x=0;x<MAPX;x++) {
X for(y=0;y<MAPY;y++) {
X /*add to attractiveness for unowned sectors*/
X if(sct[x][y].owner == 0) {
X attr[x][y]+=100;
X } else {
X if(sct[x][y].owner == NNOMAD)
X attr[x][y]+=25;
X }
X }
X }
X if(is_habitable(x,y) == 0) attr[x][y] /= 5;
X}
Xvoid
Xn_defend(natn)
Xregister short natn;
X{
X int x,y;
X
X /* add 1/10th of soldiers in sector */
X for(x=1;x<MAXARM;x++) if(ntn[natn].arm[x].sold > 0)
X if(sct[ntn[natn].arm[x].xloc][ntn[natn].arm[x].yloc].owner==country)
X attr[ntn[natn].arm[x].xloc][ntn[natn].arm[x].yloc] +=
X ntn[natn].arm[x].sold/10;
X
X /*plus 80 if near your capitol */
X for(x=ntn[country].capx-1;x<=ntn[country].capy+1;x++){
X for(y=ntn[country].capy-1;y<=ntn[country].capy+1;y++){
X if(ONMAP) attr[x][y]+=80;
X }
X }
X
X /*plus based on defensive value*/
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
X if(movecost[x][y]==1) attr[x][y] += 50;
X else if(movecost[x][y]<=3) attr[x][y] += 20;
X else if(movecost[x][y]<=5) attr[x][y] += 10;
X
X if((sct[x][y].designation==DCITY)
X &&((sct[x][y].owner==country)||(sct[x][y].owner==natn))){
X attr[x][y] += 50;
X }
X }
X}
X
Xvoid
Xn_attack(nation)
Xregister short nation;
X{
X register int x,y;
X
X /*plus 40 if next to their capitol */
X for(x=ntn[nation].capx-1;x<=ntn[nation].capy+1;x++){
X for(y=ntn[nation].capy-1;y<=ntn[nation].capy+1;y++){
X if((sct[x][y].owner==nation)&&(ONMAP))
X attr[x][y]+=40;
X }
X }
X
X /*plus 100 if on their capitol*/
X attr[ntn[nation].capx][ntn[nation].capy]+=100;
X}
X
X/* +100 if undefended sectors of nation, +60 if not */
Xvoid
Xn_undefended( nation )
X{
X register int x,y;
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==nation){
X if(is_habitable(x,y) == 0) {
X attr[x][y] += 30;
X } else if(occ[x][y]==0) {
X attr[x][y]+=100;
X } else {
X attr[x][y]+=60;
X }
X }
X}
X
X/* +60 if between two capitols */
Xvoid
Xn_between(nation)
Xint nation;
X{
X int x1,x2,y1,y2,x,y;
X
X /*plus if strategic blocking sector*/
X
X /*+60 if between the two capitol*/
X if (ntn[nation].capx < ntn[country].capx){
X x1=ntn[nation].capx;
X x2=ntn[country].capx;
X } else {
X x1=ntn[country].capx;
X x2=ntn[nation].capx;
X }
X if (ntn[nation].capy < ntn[country].capy){
X y1=ntn[nation].capy;
X y2=ntn[country].capy;
X }
X else {
X y1=ntn[country].capy;
X y2=ntn[nation].capy;
X }
X
X for(x=x1;x<=x2;x++) for(y=y1;y<=y2;y++) {
X if(ONMAP) attr[x][y]+=60;
X }
X}
X
X/* if in jeopardy, move to survive
X * if within two of cap add 1/5th of men
X * if on cap and war and 2x your garrison go jihad and + 1/2 men
X */
Xvoid
Xn_survive()
X{
X register struct army *aptr;
X int nation,armynum;
X
X if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
X attr[ntn[country].capy][ntn[country].capy]=1000;
X }
X
X /*defend your capitol if occupied, +50 more if with their army*/
X for(nation=1;nation<MAXNTN;nation++)
X if((ntn[nation].active != 0)
X &&((ntn[nation].dstatus[country]>=WAR)
X ||(ntn[country].dstatus[nation]>=WAR))){
X for(armynum=1;armynum<MAXARM;armynum++)
X if(ntn[nation].arm[armynum].sold > 0) {
X
X aptr = &(ntn[nation].arm[armynum]);
X
X if((aptr->xloc==ntn[nation].capx)
X &&(aptr->yloc==ntn[nation].capy)){
X if(aptr->sold>2*ntn[country].arm[0].sold){
X attr[aptr->xloc][aptr->yloc]+=
X aptr->sold/2;
X } else {
X attr[aptr->xloc][aptr->yloc]+=
X aptr->sold/5;
X }
X }
X else if((aptr->xloc<=ntn[nation].capx+2)
X &&(aptr->xloc>=ntn[nation].capx-2)
X &&(aptr->yloc<=ntn[nation].capy+2)
X &&(aptr->yloc>=ntn[nation].capy-2)){
X attr[aptr->xloc][aptr->yloc]+=aptr->sold/5;
X
X }
X }
X }
X}
X
Xvoid
Xdefattr()
X{
X int nation;
X
X n_unowned();
X
X for(nation=1;nation<MAXNTN;nation++)
X if((ntn[nation].active!=0)&&(ntn[country].dstatus[nation]>=WAR)) {
X n_defend(nation);
X n_between(nation);
X n_undefended(nation);
X }
X
X n_toofar();
X n_survive();
X}
X
X/*calculate attractiveness of attacking sectors*/
Xvoid
Xatkattr()
X{
X int nation;
X
X n_unowned();
X
X /*adjust for each nation that you are at war with*/
X for(nation=1;nation<MAXNTN;nation++)
X if(ntn[country].active!=0)
X if(ntn[country].dstatus[nation]==WAR) {
X n_between(nation);
X n_undefended(nation);
X n_attack(nation);
X } else if(ntn[country].dstatus[nation]==JIHAD) {
X n_attack(nation);
X n_attack(nation);
X n_between(nation);
X n_undefended(nation);
X n_attack(nation);
X n_between(nation);
X n_undefended(nation);
X n_attack(nation);
X }
X
X n_toofar();
X n_survive();
X}
X
X/*calculate attractiveness when at peace*/
Xint
Xpceattr()
X{
X n_unowned();
X n_atpeace();
X n_toofar();
X n_survive();
X}
X#endif
X
X#ifdef DEBUG
Xcheck(line)
Xint line;
X{
X int armynum;
X for(armynum=0;armynum<MAXARM;armynum++)
X if(ASOLD<0) {
X printf("ERROR: line %d army %d nation %s soldier %d\n",line,armynum,ntn[country].name,ASOLD);
X ASOLD=0;
X }
X if((AXLOC>MAPX)||(AYLOC>MAPY)){
X printf("CHECK ERROR: line %d army %d nation %s loc %d %d\n",line,armynum,ntn[country].name,AXLOC,AYLOC);
X }
X if(ntn[country].tiron < 0L)
X printf("ERROR: line %d nation %s iron is %ld\n",line,ntn[country].name,ntn[country].tiron);
X if(ntn[country].tfood < 0L)
X printf("ERROR: line %d nation %s food is %ld\n",line,ntn[country].name,ntn[country].tfood);
X if(ntn[country].jewels < 0L)
X printf("ERROR: line %d nation %s jewels is %ld\n",line,ntn[country].name,ntn[country].jewels);
X}
X#endif DEBUG
END_OF_npc.c
if test 28401 -ne `wc -c <npc.c`; then
echo shar: \"npc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 2 \(of 8\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 8 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives: